package com.wanshi.servlet;

import com.wanshi.entity.Product;
import com.wanshi.entity.User;
import com.wanshi.service.CartService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@WebServlet("/order/onlinePay")
public class onlinePay extends HttpServlet {

    CartService cartService = new CartService();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        //跳转到 选择收货地址,支付方式的界面   显示当前购物车购买的所有商品
        //查询到购物车中的所有商品
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");

        Map<Product,Integer> map = cartService.findCartByUserId(user.getId()+"");

        //存入request域,请求转发到jsp
        request.setAttribute("map",map);
        request.getRequestDispatcher("/order/addOrder.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

